<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Frederic Descamps <lefred@tiscali.be>
 * Copyright (C) 2011-     Laurent Luyssen   <big.lol13@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
?>

<html>
<body>
<?php 
$locales = array('C',  
	'POSIX',
	'en', 
	'en_AG', 
	'en_AU',
	'en_BW',
	'en_CA',
	'en_DK',
	'en_GB',
	'en_HK',
	'en_IE',
	'en_IN',
	'en_IN',
	'en_NG',
	'en_NG',
	'en_NZ',
	'en_PH',
	'en_SG',
	'en_US',
	'en_ZA',
	'en_ZW',
	'fr',
	'fr_FR',
	'fr_BE',
	'fr_CA',
	'fr_LU',
	'fr_CH',
	'de',
	'de_DE',
	'de_AT',
	'it',
	'it_IT',
	'it_CH'
	);
	
function testLocale($locale) {
	return setlocale(LC_MESSAGES , $locale);
}

function displayTestResult($locale, $result) {
	echo '<tr>';
	echo '<td>'.$locale.'</td>';
	if ($result === FALSE) {
		echo '<td><font color="red">FAIL</font></td>';
		echo '<td>false</td>';
	}
	else {
		echo '<td><font color="green">OK</font></td>';
		echo '<td>'.$result.'</td>';
	}
	echo "<tr>\n";
}
$tableHeader = '<table><th>locale</th><th>Supported</th><th>Value returned by setlocale()</th>';
if (!isset($_GET['locale']) || ($_GET['locale'] == '') )
{
	echo '<h1>Supported locales</h1>';
	echo '<pre>';
	$rc = @system('locale -a');
	echo '</pre>';
	if ($rc === false) {
		echo 'Failed to list supported locales. Testing them individually<BR>';	
		echo $tableHeader;
		foreach ($locales as $locale) {
			displayTestResult($locale, testLocale($locale) );
			displayTestResult($locale.".utf8", testLocale($locale.'.utf8') );
		}
		echo '</table>';
	}
}
else {
	echo $tableHeader;
	$locale = $_GET['locale'];
	displayTestResult($locale, testLocale($locale) );
	displayTestResult($locale.".utf8", testLocale($locale.'.utf8') );
	echo '</table>';
}
echo '<br/><h1>Test a locale</h1>';
echo '<form action="'.$_SERVER["SCRIPT_NAME"].'" method="GET">';
?>

Locale : <input type="text" name="locale" />
<input type="submit" value="Submit" />
</form> 
</body>
</html>



